//
//  UINavigationBar+CMC.m
//  Mobile4S
//
//  Created by Nong Trung Nghia on 8/17/12.
//
//

#import "UINavigationBar+CMC.h"

@implementation UINavigationBar (CMC)

-(void)setBackgroundImage:(UIImage*)image{
    if(image == NULL){ //might be called with NULL argument
        return;
    }
    UIImageView *aTabBarBackground = [[UIImageView alloc]initWithImage:image];
//    NSLog(@"%@",self.subviews);
    aTabBarBackground.frame = CGRectMake(0,0,self.frame.size.width,self.frame.size.height+4);
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UINavigationBarBackground")]) {
//            NSLog(@"remove background");
            [view removeFromSuperview];
        }
        if ([view isKindOfClass:NSClassFromString(@"UINavigationItemView")]) {
//            NSLog(@"%@",view.subviews);
        }
    }
    [self addSubview:aTabBarBackground];
    [self sendSubviewToBack:aTabBarBackground];
    [aTabBarBackground release];
}

@end
